import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class studentDelete {

        public static void main(String[] args) throws SQLException {
            //建立数据源
            DataSource dataSource=new MysqlDataSource();
            ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java104?characterEncoding=utf8&useSSL=false");
            ((MysqlDataSource)dataSource).setUser("root");
            ((MysqlDataSource)dataSource).setPassword("666666");

            //创建链接
            Connection connection=dataSource.getConnection();
            System.out.println(connection);

            //构建sql语句
            Scanner scanner=new Scanner(System.in);
            System.out.println("输入删除学生学号");
            int id=scanner.nextInt();
            System.out.println("输入删除学生姓名");
            String name=scanner.next();
            String sqlDelete="delete from student where id=? && name=? ;";
            PreparedStatement ps=connection.prepareStatement(sqlDelete);
            ps.setInt(1,id);
            ps.setString(2,name);
            ps.executeUpdate();

            //释放资源
            ps.close();
            connection.close();
        }

}
